#include<iostream>
#include<vector>
using namespace std;
vector<int> v[10005];
int main(){
	int n,m,a,b;
	cin >> n >> m;
	for(int i=1;i<=n;i++){
		v[i].push_back(i);
	}
	for(int i=0;i<m;i++){
		cin >> a >> b;
		if(a==b){
			continue;
		}
		for(int j=0;j<v[b].size();j++){
			v[a].push_back(v[b][j]);
		}
		vector<int>().swap(v[b]); 
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<v[i].size();j++){
			if(j!=v[i].size()-1){
				cout << v[i][j] << " ";
			}else{
				cout << v[i][j];
			}
		}
		cout << endl;
	}
	return 0;
}
